rendernodeparser: Skip root node when it's a container
authorBenjamin Otte <otte@redhat.com>
Tue, 14 May 2019 00:49:19 +0000 (02:49 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 21 May 2019 04:43:59 +0000 (06:43 +0200)
When printing, behave the same way as when parsing:
Magically skip a container node if there is one - just like the
parser magically creates a container node to hold all the nodes
it parses.

gsk/gskrendernode.c
gsk/gskrendernodeparser.c
gsk/gskrendernodeparserprivate.h

index 1b1dd2d78f653a3b573aa475d52d1f9673ec54f5..2e4753a2e010db9b497d613d0f5e5c80b7d6f3c5 100644 (file)
@@ -310,34 +310,6 @@ gsk_render_node_diff (GskRenderNode  *node1,
 #define GSK_RENDER_NODE_SERIALIZATION_VERSION 0
 #define GSK_RENDER_NODE_SERIALIZATION_ID "GskRenderNode"
 
-/**
- * gsk_render_node_serialize:
- * @node: a #GskRenderNode
- *
- * Serializes the @node for later deserialization via
- * gsk_render_node_deserialize(). No guarantees are made about the format
- * used other than that the same version of GTK+ will be able to deserialize
- * the result of a call to gsk_render_node_serialize() and
- * gsk_render_node_deserialize() will correctly reject files it cannot open
- * that were created with previous versions of GTK+.
- *
- * The intended use of this functions is testing, benchmarking and debugging.
- * The format is not meant as a permanent storage format.
- *
- * Returns: a #GBytes representing the node.
- **/
-GBytes *
-gsk_render_node_serialize (GskRenderNode *node)
-{
-  GBytes *result;
-  char *str;
-
-  str = gsk_render_node_serialize_to_string (node);
-  result = g_bytes_new_take (str, strlen (str));
-
-  return result;
-}
-
 /**
  * gsk_render_node_write_to_file:
  * @node: a #GskRenderNode
index caf601d401bd3f726900d80f23941ed04c49a9f5..b9603b235e19e0f4571f0ab550837ef9d981ecb9 100644 (file)
@@ -1,3 +1,25 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *                  Timm Bäder
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ *          Timm Bäder <mail@baedert.org>
+ */
+
+#include "config.h"
 
 #include "gskrendernodeparserprivate.h"
 
@@ -1945,13 +1967,44 @@ render_node_print (Printer       *p,
     }
 }
 
-char *
-gsk_render_node_serialize_to_string (GskRenderNode *root)
+/**
+ * gsk_render_node_serialize:
+ * @node: a #GskRenderNode
+ *
+ * Serializes the @node for later deserialization via
+ * gsk_render_node_deserialize(). No guarantees are made about the format
+ * used other than that the same version of GTK+ will be able to deserialize
+ * the result of a call to gsk_render_node_serialize() and
+ * gsk_render_node_deserialize() will correctly reject files it cannot open
+ * that were created with previous versions of GTK+.
+ *
+ * The intended use of this functions is testing, benchmarking and debugging.
+ * The format is not meant as a permanent storage format.
+ *
+ * Returns: a #GBytes representing the node.
+ **/
+GBytes *
+gsk_render_node_serialize (GskRenderNode *node)
 {
   Printer p;
 
   printer_init (&p);
-  render_node_print (&p, root);
 
-  return g_string_free (p.str, FALSE);
+  if (gsk_render_node_get_node_type (node) == GSK_CONTAINER_NODE)
+    {
+      guint i;
+
+      for (i = 0; i < gsk_container_node_get_n_children (node); i ++)
+        {
+          GskRenderNode *child = gsk_container_node_get_child (node, i);
+
+          render_node_print (&p, child);
+        }
+    }
+  else
+    {
+      render_node_print (&p, node);
+    }
+
+  return g_string_free_to_bytes (p.str);
 }
index a506244429dfa02fcd58648157da1df7af3df763..7994488772388d9e79c74a08e4c1739fc230b9a6 100644 (file)
@@ -7,6 +7,5 @@
 GskRenderNode * gsk_render_node_deserialize_from_bytes  (GBytes            *bytes,
                                                          GskParseErrorFunc  error_func,
                                                          gpointer           user_data);
-char *          gsk_render_node_serialize_to_string     (GskRenderNode *root);
 
 #endif